<?php
    require 'phpclasses/userclass.php';
    require 'phpclasses/userprofileclass.php';
    
    isset($_POST['userid']) ? $userid = $_POST['userid'] : $userid = 0;
    isset($_POST['name']) ? $name = $_POST['name'] : $name = '';
    isset($_POST['surname']) ? $surname = $_POST['surname'] : $surname = '';
    isset($_POST['email']) ? $email = $_POST['email'] : $email = '';
    isset($_POST['gender']) ? $gender = $_POST['gender'] : $gender = '';
    isset($_POST['dobday']) ? $dobday = $_POST['dobday'] : $dobday = 0;
    isset($_POST['dobmonth']) ? $dobmonth = $_POST['dobmonth'] : $dobmonth = 0;
    isset($_POST['dobyear']) ? $dobyear = $_POST['dobyear'] : $dobyear = 0;
    isset($_POST['job']) ? $job = $_POST['job'] : $job = '';
    isset($_POST['town']) ? $town = $_POST['town'] : $town = '';
    
    isset($_POST['partnerid']) ? $partnerid = $_POST['partnerid'] : $partnerid = 0;
    isset($_POST['partnername']) ? $partnername = $_POST['partnername'] : $partnername = '';
    isset($_POST['partnersurname']) ? $partnersurname = $_POST['partnersurname'] : $partnersurname = '';
    isset($_POST['partneremail']) ? $partneremail = $_POST['partneremail'] : $partneremail = '';
    isset($_POST['partnergender']) ? $partnergender = $_POST['partnergender'] : $partnergender = '';
    isset($_POST['partnerdobday']) ? $partnerdobday = $_POST['partnerdobday'] : $partnerdobday = 0;
    isset($_POST['partnerdobmonth']) ? $partnerdobmonth = $_POST['partnerdobmonth'] : $partnerdobmonth = 0;
    isset($_POST['partnerdobyear']) ? $partnerdobyear = $_POST['partnerdobyear'] : $partnerdobyear = 0;
    isset($_POST['partnerjob']) ? $partnerjob = $_POST['partnerjob'] : $partnerjob = '';
    isset($_POST['partnertown']) ? $partnertown = $_POST['partnertown'] : $partnertown = '';

    if($userid > 0){
        // Save user info
        $user = new userclass();
        $user->initwithuserid($userid);
        
        $user->name = $name;
        $user->surname = $surname;
        $user->email = $email;
        
        $usersaveoutput = $user->saveself();
        
        // Save user profile info
        $userprofile = new userprofileclass();
        $userprofile->initwithuserid($userid);
        
        $userprofile->setgender($gender);
        $userprofile->setdob($dobday, $dobmonth, $dobyear);
        $userprofile->job = $job;
        $userprofile->town = $town;
        
        $userprofilesaveoutput = $userprofile->saveself();
    }
    
    if($partnerid > 0){
        // Save user partner info
        $partner = new userclass();
        $partner->initwithuserid($partnerid);
        
        $partner->name = $partnername;
        $partner->surname = $partnersurname;
        $partner->email = $partneremail;
        
        $partnersaveoutput = $partner->saveself();
        
        // Save user partner profile info
        $partnerprofile = new userprofileclass();
        $partnerprofile->initwithuserid($partnerid);

        $partnerprofile->setgender($partnergender);
        $partnerprofile->setdob($partnerdobday, $partnerdobmonth, $partnerdobyear);
        $partnerprofile->job = $partnerjob;
        $partnerprofile->town = $partnertown;
        
        $partnerprofilesaveoutput = $partnerprofile->saveself();
    }

    if(isset($_GET['retpage']))
        $retpage = $_GET['retpage'];
    else
        $retpage = 'couple.php';

    if(isset($_GET['showitem']))
        $returl = $retpage.'?showitem='.$_GET['showitem'];
    else
        $returl = $retpage;

    header('Location: '.$returl);
    exit();
?>